// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AdminCommandGroup.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Extensions.Admin
{
    #region Using Directives

    using System.Collections.Generic;

    using Org.OpenTrader.Extensions.Admin.UI.Forms;
    using Org.OpenTrader.Framework;
    using Org.OpenTrader.Framework.CommandGroups;
    using Org.OpenTrader.Framework.UI.Forms;

    #endregion

    /// <summary>
    /// The admin command group.
    /// </summary>
    public class AdminCommandGroup : CommandGroup
    {
        #region Constants and Fields

        /// <summary>
        /// The commands.
        /// </summary>
        private readonly IDictionary<string, Command> commands;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="AdminCommandGroup"/> class.
        /// </summary>
        public AdminCommandGroup()
        {
            this.commands = new Dictionary<string, Command>();

            Command cmd;

            cmd = new UICommand(this);
            this.commands[cmd.Name] = cmd;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets Commands.
        /// </summary>
        public override IDictionary<string, Command> Commands
        {
            get
            {
                return this.commands;
            }
        }

        /// <summary>
        /// Gets Help.
        /// </summary>
        public override string Help
        {
            get
            {
                return "This command group is used to perform administrative tasks in Open Trader";
            }
        }

        /// <summary>
        /// Gets Name.
        /// </summary>
        public override string Name
        {
            get
            {
                return "admin";
            }
        }

        #endregion

        /// <summary>
        /// The ui command.
        /// </summary>
        public class UICommand : Command
        {
            #region Constants and Fields

            /// <summary>
            /// The identity.
            /// </summary>
            private static readonly Identity Identity = Identity.Create(System.Reflection.MethodBase.GetCurrentMethod());

            #endregion

            #region Constructors and Destructors

            /// <summary>
            /// Initializes a new instance of the <see cref="UICommand"/> class.
            /// </summary>
            /// <param name="commandGroup">
            /// The command group.
            /// </param>
            public UICommand(CommandGroup commandGroup)
                : base(commandGroup)
            {
            }

            #endregion

            #region Properties

            /// <summary>
            /// Gets Help.
            /// </summary>
            public override string Help
            {
                get
                {
                    return "starts administrative graphical user interface";
                }
            }

            /// <summary>
            /// Gets Name.
            /// </summary>
            public override string Name
            {
                get
                {
                    return "ui";
                }
            }

            /// <summary>
            /// Gets Usage.
            /// </summary>
            public override string Usage
            {
                get
                {
                    return string.Format("{0} {1}", this.CommandGroup.Name, this.Name);
                }
            }

            #endregion

            #region Public Methods

            /// <summary>
            /// The execute.
            /// </summary>
            /// <param name="args">
            /// The args.
            /// </param>
            /// <returns>
            /// </returns>
            public override Status Execute(string[] args)
            {
                UIRootControl rctrl = new UIAdmin();
                rctrl.Run("OpenTrader Admin Interface");

                return Status.Success(Identity);
            }

            #endregion
        }
    }
}